class FindFile:
# 初始化方法，用于打开文件并读取所有行
	def __init__(self, file_name):
    # 将传入的文件名保存为实例变量
		self.file_name = file_name
    # 以只读模式打开文件，并将文件对象保存为实例变量
		self.file = open(file_name, 'r')
    # 读取文件的所有行，并将结果保存为实例变量
		self.all_lines = self.file.readlines()

	def find_key(self, key, case_sensitive=True):
		if case_sensitive:
			return [i for i, line in enumerate(self.all_lines) if key in line]
		else:
			return [i for i, line in enumerate(self.all_lines) if key.lower() in line.lower()]

	def find_BunderA(self, A, B, case_sensitive=True):
		re_list = []
		if case_sensitive:
			for i, A_line in enumerate(self.all_lines):
				if A in A_line:
					for j, B_line in enumerate(self.all_lines[i:]):
						if B in B_line:
							re_list.append((i, j))
							break
		else:
			A = A.lower()
			B = B.lower()
			for i, A_line in enumerate(self.all_lines):
				if A in A_line.lower():
					for j, B_line in enumerate(self.all_lines[i:]):
						if B in B_line.lower():
							re_list.append((i,j))
							break
		return re_list

	def close_file(self):
		self.file.close()


afile = "E:\\vscode\gitee\\back_end\py_check\conf.py"
f = FindFile(afile)

print(f.find_key("PIN"))
print(f.find_BunderA("PIN", "DIRECTION"))